﻿using Kingdee.BOS;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;

namespace Caraya.MFG.BusinessPlugIn
{
    [Description("二开模拟报价单插件"), HotUpdate]
    public class SimulateQuoteEdit : Kingdee.BOS.Core.DynamicForm.PlugIn.AbstractDynamicFormPlugIn
    {
        public override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            double Fsew = double.Parse(this.Model.GetValue("FQTAXPRICE").ToString()) / 6.5d;
            if (!(this.Model.DataObject["FQMaterialId"] is DynamicObject obj)) return;
            var ft = obj["F_BP_ProTypes"] as DynamicObject;
            if (ft != null)
            {
                var name = (LocaleValue)ft["Name"];
                var FName = name.ToString();
                var FName1 = name.ToString(CultureInfo.CurrentCulture);
                Debug.WriteLine(FName);
                Debug.WriteLine(FName1);
            }
            var f1 = ft[2] as DynamicObjectCollection;
            var f2 = f1[0][2];

            this.Model.SetValue("F_typeText", f2.ToString());
            this.Model.SetValue("F_USAPrice", Fsew.ToString("N2"));
        }

        public override void DataChanged(DataChangedEventArgs e)
        {
            base.DataChanged(e);
            if (e.Field.Key == "FTaxPrice")
            {
                double Fsew = double.Parse(e.NewValue.ToString()) / 6.5d;
                this.Model.SetValue("F_USAPrice", Fsew.ToString("N2"));
            }
        }

        /// <summary>
        /// 获取多选辅助资料的名称（多个名称用分号分割）
        /// </summary>
        /// <param name="field"></param>
        /// <param name="objs"></param>
        /// <returns></returns>        
        private LocaleValue GettMulAssistantName(MulAssistantField field, DynamicObjectCollection objs)
        {
            var lv = new LocaleValue();
            if (objs == null | objs.Count == 0)
            { return lv; }
            foreach (var obj in objs)
            {
                if (obj[field.PropertyName] is DynamicObject assistant)
                {
                    var name = (LocaleValue)assistant["FDataValue"];
                    lv.Merger(name, ";");
                }
            }
            return lv;
        }


    }
}
